package com.bgthrid;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kldy8.kldyw.R;

/**
 * Created by user on 2016/10/31.
 */

public class ImageTextButton extends RelativeLayout
{

    private ImageView imgView;
    private TextView textView;
    private TextView imgtextview;
    private String text = "";
    private String imgtext = "";


    public ImageTextButton(Context context) {
        super(context,null);
    }

    public ImageTextButton(Context context,AttributeSet attributeSet) {
        super(context, attributeSet);

        int btnSize = -1;
        btnSize = attributeSet.getAttributeIntValue(null, "btnSize", 0);

        if (btnSize > 0)
        {
            LayoutInflater.from(context).inflate(R.layout.img_text_big, this,true);
        }
        else
        {
            LayoutInflater.from(context).inflate(R.layout.img_text_bt, this,true);
        }

//        LayoutInflater.from(context).inflate(R.layout.img_text_bt, this,true);

        this.imgView = (ImageView)findViewById(R.id.imgview);
        this.textView = (TextView)findViewById(R.id.textview);
        this.imgtextview = (TextView)findViewById(R.id.imgtextview);

        int resouceId = -1;
        int resouceImageId = -1;
        int resouceImageTextId = -1;

        resouceId = attributeSet.getAttributeResourceValue(null, "mtext", 0);
        resouceImageId = attributeSet.getAttributeResourceValue(null, "mImage", 0);
        resouceImageTextId = attributeSet.getAttributeResourceValue(null, "mImageText", 0);

        if (resouceId > 0) {
            text = context.getResources().getText(resouceId).toString();
        } else
        {
            text = "";
        }
        textView.setText(text);

        if (resouceImageId > 0)
        {
            Drawable drawable = context.getResources().getDrawable(resouceImageId);
            imgView.setBackground(drawable);
        }
        else
        {

        }

        if (resouceImageTextId > 0) {
            imgtext = context.getResources().getText(resouceImageTextId).toString();
        }
        else
        {
            imgtext = "";
        }
        imgtextview.setText(imgtext);

        this.setClickable(true);
        this.setFocusable(true);
    }

    public void setImgResource(int resourceID) {
        this.imgView.setImageResource(resourceID);
    }

    public void setText(String text) {
        this.textView.setText(text);
    }

    public void setTextColor(int color) {
        this.textView.setTextColor(color);
    }

    public void setTextSize(float size) {
        this.textView.setTextSize(size);
    }



}